/**
 * 
 */
package run;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import database.SetConn;
import eb.User;

/**
 * @author ys
 * 
 */
public class UserInfo {
	private Connection conn = null;
	private User currentUser;

	public void updateInfo(User user) {
		SetConn testconn = new SetConn();
		conn = testconn.setupConn();
		String userName = user.GetUserName();
		String realName = user.GetRealName();
		String sex = user.GetSex();
		String tel = user.GetTel();
		String email = user.GetEmail();
		String address = user.GetAddress();
		String postcode = user.GetPostcode();
		String sql = "update member set RealName='" + realName + "', Sex='"
				+ sex + "', Tel='" + tel + "', Email='" + email
				+ "', Address='" + address + "', Postcode='" + postcode
				+ "' where UserName='" + userName + "'";
		try {
			PreparedStatement stmt = conn.prepareStatement(sql);
			int result = stmt.executeUpdate();

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public void updatePasswd(User userInfo) {
		SetConn testconn = new SetConn();
		conn = testconn.setupConn();
		String userName = userInfo.GetUserName();
		String passwd = userInfo.GetPassWord();
		String sql = "update member set Password='" + passwd
				+ "' where UserName='" + userName + "'";
		try {
			PreparedStatement stmt = conn.prepareStatement(sql);
			int result = stmt.executeUpdate();

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
	public void updatePasswd(String userName, String newPasswd) {
		SetConn testconn = new SetConn();
		conn = testconn.setupConn();
		String sql = "update member set Password='" + newPasswd
				+ "' where UserName='" + userName + "'";
		try {
			PreparedStatement stmt = conn.prepareStatement(sql);
			int result = stmt.executeUpdate();

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	
/*	public void updatePasswd(String userName, String oldPasswd, String newPasswd, String verifyPasswd) {
		SetConn testconn = new SetConn();
		conn = testconn.setupConn();
		String sql = "update member set Password='" + newPasswd
				+ "' where UserName='" + userName + "'";
		try {
			PreparedStatement stmt = conn.prepareStatement(sql);
			int result = stmt.executeUpdate();

		} catch (SQLException e) {
			e.printStackTrace();
		}
	}*/

}
